Skip to content

fix(daemon): enforce the source-install request deadline - #4727

Merged
thymikee merged 4 commits into
mainfrom
t3/source-install-daemon-deadline
Nov 19, 2026
Merged

thymikee merged 4 commits into
mainfrom
t3/source-install-daemon-deadline

Conversation

@thymikee

@thymikee thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Enforce a 570-second daemon deadline for source installs inside the existing 600-second client envelope. An earlier registered result deadline can refuse entry or abort in-flight source work. Timeout details report the effective budget. Ordinary source installs retain their lease admission behavior, and batch and replay retain their 60-second budget. For HTTP or socket requests with a registered result deadline, their timer is capped by the earlier deadline measured from transport admission.

Refs #4441. The downloader and materialization budget are covered separately in #4726.

Validation

Head 8b3511b5dd1503a3b1b7f7b8dbfa36d8795379e7.

  • 161 focused tests, formatting, lint and typecheck passed. All local exact affected checks passed, including the full unit suite.
  • The loopback HTTP/RPC tests exercise the 570-second cutoff, earlier deadline abort during execution, admission refusal, cleanup and a successful install through a provider fixture. The earlier cutoff test asserts the typed daemon_request_timeout response and the effective budget.
  • All 17 GitHub checks passed. Apex Sentinel approved 8b3511b with zero open findings. All three inline threads from 5fb8c9e are resolved.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

thymikee and others added 2 commits November 19, 2026 03:06
…ne at the descriptor/router path

Give install-from-source and install_source one shared source-install timeout
policy (#4441, decisions 6856998913/6827686874): the existing 600000ms client
envelope with a 570000ms daemonDeadlineMs derived from the 30000ms result
margin. resolveDaemonRequestTimeoutMs now returns 570000 for both commands, so
the request router wraps their execution in the existing withRequestDeadline
owner instead of running source installs under the client envelope alone.

withRequestDeadline now honors any earlier registered execution/result
deadline at admission and refuses task entry when the earliest registered
cutoff has already passed, while leaving mid-task execution enforcement,
callback cancellation, unrelated command policies and the native-install caps
untouched. A request without transport metadata still gets the finite
570000ms budget from its descriptor.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
… daemon deadline (#4441)

Loopback HTTP/RPC ingress feeding the real request router and the normal
provider-backed source-install path (only the provider gateway seam is faked),
under controlled clocks. Proves on top of the descriptor candidate: the 570s
daemon deadline expiring at exactly admission+570000ms with a typed
daemon_request_timeout error and no success on the wire; work crossing the
cutoff mid-task aborted with artifact cleanup; the streaming route answering
the typed error in-stream after response headers were already sent, with the
request lifetime released; task entry refused when an earlier registered
result deadline already passed, while a live earlier deadline is the effective
cutoff an admitted request observes; plus an ordinary benign success control.

Detection: 6/6 pass on the candidate; on clean origin/main 6e18ea3 and on a
deadline-removal mutation of the candidate, the four detecting cases fail
(daemon never answers within the 570s budget; entry not refused).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.39 MB 6.39 MB +222 B
Package (unpacked) 6.39 MB 6.39 MB +222 B
Package (download) 1.94 MB 1.94 MB +76 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 22.0 ms 20.7 ms -1.3 ms
CLI --help 44.9 ms 42.7 ms -2.2 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed aa4f988. The change needs one rework before merge: the new deadline helper duplicates an existing rule and leaves a gap in the request deadline. All 18 checks are green at this commit, and I know of no conflicts.

earliestRegisteredDeadlineMs computes the minimum of the execution deadline and resultDeadlineMs. getRequestDeadlineMs (L219-225) already does the same thing nine lines above. Two spellings of "the request's earliest cutoff" can drift apart, and then the entry refusal would disagree with what touch-press, the Android automation helper and materialization observe. Please keep one definition and remove earliestRegisteredDeadlineMs and refuseIfEarliestDeadlineExpired.

The same fix closes a gap. withRequestDeadline arms Date.now() + timeoutMs at router entry (L316). The timer only re-arms on the execution deadline, and resultDeadlineMs is checked once at entry (L337). If an auth hook or other pre-router work takes T seconds, the request is cut at admission + 570 s + T. A result deadline that expires after entry never aborts the task. The rule should be that the router's armed cutoff is the earliest registered cutoff for the whole request lifetime. Could withRequestDeadline use Math.min(Date.now() + timeoutMs, controller.resultDeadlineMs ?? Number.POSITIVE_INFINITY)? The existing enforceExecutionDeadline at entry would then refuse expired work, and the existing timer would enforce it mid-task. That also removes about 20 production lines. The descriptor change can stay as it is.

The test a live earlier result deadline is the effective cutoff only checks that getRequestDeadlineMs returns the earlier deadline. That already held on base, so the test passes without this PR. After the fix above, please advance the fake clock past the earlier result deadline while the provider task is pending. Then assert daemon_request_timeout and no deploy call.

Not blocking, take or leave: postRpc copies postRpcRaw from http-server-rpc.fixtures.ts, so the shared helper could take an optional answer deadline instead. The new test in daemon-command-registry.test.ts sits between an existing comment and the test that comment describes, so it should move above that comment.

No device run is needed here. The combined proxy to daemon to downloader path stays with #4441.

@thymikee

Copy link
Copy Markdown
Member Author

Addressed the review of aa4f988 in 5fb8c9ef4e. The existing execution timer now arms at the earlier of the router budget and the registered result deadline. Both duplicate helpers are gone.

The router test keeps materialization pending, advances the clock past the earlier cutoff, and asserts daemon_request_timeout with zero deploy calls. It failed at aa4f988 because the provider signal stayed live. The host-kit test also covers enforcing the cutoff before timer delivery.

All 69 focused tests, lint, and typecheck passed. Exact affected validation and hosted CI are running. I moved the registry comment and kept the real-clock RPC fixture for the fake-clock route tests.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 3 new findings on 5fb8c9e. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Addressed the three follow-up findings in 8b3511b5dd.

  • A top-level source install keeps its normal admission path while a batch or replay source-install step still uses bounded composite rules. The router regression fails with the previous classification.
  • Requests that already have an execution timer keep honoring the earliest registered cutoff. A test pins the batch and replay transport deadlines to their resolved execution budgets.
  • The timeout reports the effective budget from router entry. The regression checks 60 seconds when an earlier result deadline fires, and zero when admission is already expired.

All 161 focused tests, lint, and typecheck passed. Exact affected validation and hosted CI are running.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 8b3511b

Since the review of 5fb8c9e: 0 new · 0 still open · 3 no longer raised

No open findings.

2 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (b566dca171dc).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

I reviewed 8b3511b against my earlier findings at aa4f988 (#4727 (comment)). The code looks right and I have no blocking findings. The earlier findings are fixed: top-level install_source/install-from-source now go through normal admission in lease-context.ts, and daemon-command-registry.test.ts:359 now pins the result deadline for batch and replay. All 17 checks pass at 8b3511b. No conflicts.

Not blocking, and you can take or leave these: lease-context.ts:36 still infers a bounded batch/replay step from the presence of any execution deadline, so the next command with a daemonDeadlineMs will need another command-name branch; and the PR body says batch and replay "retain their existing timer policy", but request-cancel.ts:294 now measures their 60 s budget from transport admission, so the body could say that instead.

Could isBoundedCompositeRequest be defined by the markers the composites already stamp, for every command: req.internal?.executionPlan !== undefined || req.internal?.replayPlanStep === true? That would remove the install-source branch and the catalog import, and a later deadline on any command could not change lease or claim admission. First, please confirm that every request dispatched under a batch or replay deadline carries one of those two markers, and stamp the marker at any replay lifecycle dispatch that bypasses the replay action runtime.

On the earlier inline threads: the thread on the install-source admission route (#4727 (comment)), the one on the batch/replay budget split (#4727 (comment)) and the one on the reported deadline value (#4727 (comment)) are all fixed at this head, so please resolve them. No other threads remain open that still apply.

Nothing blocks merge. The only open item is the design question above, which you can answer or take.

@thymikee

Copy link
Copy Markdown
Member Author

The markers are the right source for identifying ordinary composite steps. runBatchCommands stamps executionPlan on every invoked batch step. Authored replay actions, including open and close, get replayPlanStep in invokeResolvedReplayAction. The dispatch envelope preserves that marker into the scoped router.

There is one bypass to account for before changing the predicate globally. A replay test can run as a bounded batch step. Its suite-owned cleanup calls handleSessionCloseCommands directly with the parent request ID and a cleanupIntent, but no executionPlan or replayPlanStep. A marker-only predicate would stop recognizing that cleanup as bounded. The existing replay marker also controls authored recording provenance, so I would carry trusted composite provenance for cleanup rather than mark it as an authored replay action. I left the predicate as-is in this deadline fix.

I corrected the PR description to say that the existing 60-second batch and replay budgets can be capped by the transport-admission deadline. GitHub shows all three earlier threads resolved and all 17 checks passed at 8b3511b.

thymikee added a commit that referenced this pull request Nov 19, 2026
…base

Stacked on #4727 (5fb8c9e) so the install_source daemon deadline is
armed at admission on both daemon entry transports (HTTP /rpc and the
newline socket). Implements the two blocking findings from the #4726
review (issuecomment-7003528891):

- f1: the install_source handler now derives the materialization cutoff
  from getRequestDeadlineMs(requestId) minus the deploy-ledger reserve
  (INSTALL_SOURCE_DEPLOY_LEDGER_RESERVE_MS = 480s envelope - 30s margin
  = 450s, the install-route worst-case ledger) via the new
  getRequestBudgetSignal owner in host-kit request-cancel, which composes
  the request's shared cancellation with the remaining-deadline timeout
  (AbortSignal.any) instead of arming an independent maximum. The signal
  travels through MaterializeAppSourceInput.signal into the Android and
  Apple prepareArtifact paths, so the armed cutoff reaches
  materializeInstallablePath on both transports (proven by loopback
  router tests over HTTP RPC and socket). The standalone 600s aggregate
  stays as the fallback when no daemon deadline is armed, and the native
  phase/install caps are untouched. The install ledger test sums the
  download call again: on daemon routes the download timer is the
  derived remaining budget (<= 570s-450s), so a 600s value fails the
  600s envelope sum (red-verified against the pre-fix handler, which
  records 600000ms and fails all five install_source URL cases).
- f2: the response-header phase now arms when the upstream connection is
  established on every dispatcher the transport builds. Pinned undici
  7.30.1 (pnpm-lock) ProxyAgent never emits 'connect' (verified in
  lib/dispatcher/proxy-agent.js: it builds its own inner Agent), so the
  proxy path wraps the tunnel connector handed to the inner factory and
  fires onConnected when the CONNECT tunnel succeeds; the direct Agent
  keeps the 'connect' event. New benign owned loopback CONNECT proxy
  tests prove headers get their own 30s phase budget (headers at 35s
  succeed past the old 30s connect budget) and that stalled headers
  expire with the typed transfer_phase_timeout 'response-headers'
  result; both fail against the pre-fix transport.

Also resolves the take-or-leave items: the install-source doc names the
real deadline carrier, and classifyMaterializationError only relabels
abort-shaped errors (error === signal.reason or error.cause ===
signal.reason) so a typed failure racing an abort keeps its identity.

Refs #4441 (decisions 6827686874/6856998913), #4726, #4727.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks, that settles it. The suite-owned cleanup reaches the close handlers without either marker, so a marker-only predicate would stop treating that cleanup as bounded. Keeping the predicate as-is in this deadline fix is right, and carrying trusted composite provenance for cleanup can be a follow-up. With the body corrected and the threads resolved, this is ready for a maintainer to merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee
thymikee added this pull request to stack #4734 November 19, 2026 10:09
@thymikee
thymikee merged commit c8f29f3 into main Nov 19, 2026
17 checks passed
@thymikee
thymikee deleted the t3/source-install-daemon-deadline branch November 19, 2026 13:29
thymikee added a commit that referenced this pull request Nov 19, 2026
* feat(provision-kit): propagate source-install deadlines into download phases

Align the provision-kit source-install/download path with the adopted #4441
policy (Decisions 6827686874/6876352959):

- Remove the contradictory fixed 120s source-transfer signal. The shared
  budget from admission (request signal) now governs download and extraction;
  a standalone materialization call gets a finite 600s aggregate at entry,
  combined with caller cancellation, so the API never becomes unbounded.
- Drive the download through the existing host-kit transfer phase watchdog:
  30s connect, 30s response-header wait after connection establishment,
  120s accepted-byte inactivity. Redirect hops rearm fresh phase timers on
  the same aggregate signal.
- Wire the watchdog signal into the response-body pipeline and count accepted
  body bytes as the only progress that rearms the inactivity ceiling.
- Preserve the typed first failure: caller cancellation stays typed
  cancellation, phase timeouts keep their phase and budget, aggregate
  expiry reports source_materialization_deadline_exceeded.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

* fix(provision-kit): preserve source deadline failures before publication

* fix(provision-kit): retain hop timeout causes and verify standalone budget

* fix(provision-kit,daemon): resolve #4726 review findings on the 570s base

Stacked on #4727 (5fb8c9e) so the install_source daemon deadline is
armed at admission on both daemon entry transports (HTTP /rpc and the
newline socket). Implements the two blocking findings from the #4726
review (issuecomment-7003528891):

- f1: the install_source handler now derives the materialization cutoff
  from getRequestDeadlineMs(requestId) minus the deploy-ledger reserve
  (INSTALL_SOURCE_DEPLOY_LEDGER_RESERVE_MS = 480s envelope - 30s margin
  = 450s, the install-route worst-case ledger) via the new
  getRequestBudgetSignal owner in host-kit request-cancel, which composes
  the request's shared cancellation with the remaining-deadline timeout
  (AbortSignal.any) instead of arming an independent maximum. The signal
  travels through MaterializeAppSourceInput.signal into the Android and
  Apple prepareArtifact paths, so the armed cutoff reaches
  materializeInstallablePath on both transports (proven by loopback
  router tests over HTTP RPC and socket). The standalone 600s aggregate
  stays as the fallback when no daemon deadline is armed, and the native
  phase/install caps are untouched. The install ledger test sums the
  download call again: on daemon routes the download timer is the
  derived remaining budget (<= 570s-450s), so a 600s value fails the
  600s envelope sum (red-verified against the pre-fix handler, which
  records 600000ms and fails all five install_source URL cases).
- f2: the response-header phase now arms when the upstream connection is
  established on every dispatcher the transport builds. Pinned undici
  7.30.1 (pnpm-lock) ProxyAgent never emits 'connect' (verified in
  lib/dispatcher/proxy-agent.js: it builds its own inner Agent), so the
  proxy path wraps the tunnel connector handed to the inner factory and
  fires onConnected when the CONNECT tunnel succeeds; the direct Agent
  keeps the 'connect' event. New benign owned loopback CONNECT proxy
  tests prove headers get their own 30s phase budget (headers at 35s
  succeed past the old 30s connect budget) and that stalled headers
  expire with the typed transfer_phase_timeout 'response-headers'
  result; both fail against the pre-fix transport.

Also resolves the take-or-leave items: the install-source doc names the
real deadline carrier, and classifyMaterializationError only relabels
abort-shaped errors (error === signal.reason or error.cause ===
signal.reason) so a typed failure racing an abort keeps its identity.

Refs #4441 (decisions 6827686874/6856998913), #4726, #4727.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

* fix(providers): forward the daemon-derived materialization cutoff through Webdriver and Revyl bindings

The daemon derives the URL materialization cutoff from the earliest registered request deadline less the deploy-ledger reserve and passes it through MaterializeAppSourceInput.signal. The Webdriver and Revyl bindings dropped it and used only the binding scope signal, so a hosted download could run to the full request deadline and starve the deploy ledger. Forward the input cutoff where present and keep the scope signal as the fallback, matching the platform deployment bindings (#4441, #4726).

* test(provision-kit): prove the install ledger splits readiness from the deploy reserve

WIP: the 450s deploy-ledger reserve is the whole install ledger including readiness, but the daemon derives the materialization cutoff after ensureReady has run, so readiness is charged twice. A cold boot of 120s or more arms a zero-second cutoff and the URL install fails before a byte is fetched. The recorded per-phase sums show the deploy-only worst case is 320s.

* fix(provision-kit): carry the materialization cutoff as deadline data and split the ledger reserve

The cutoff now travels as materializationDeadlineMs on MaterializeAppSourceInput. The materializer arms one timer at min(600s aggregate, remaining) and every timer-driven abort reports source_materialization_deadline_exceeded with the timeout actually armed; only a real request cancellation reports request_canceled. This deletes getRequestBudgetSignal and the four input.signal ?? signal forwards (platform, Webdriver, and Revyl bindings): the bindings forward the input untouched and keep their scope signal for cancellation, so no provider carries deadline code.

The reserve becomes the deploy ledger's worst case without readiness (320s), with the readiness share named as INSTALL_SOURCE_READINESS_WORST_CASE_MS (150s). The cutoff is derived after ensureReady, so charging readiness to the reserve twice armed a zero-second cutoff on a cold-boot route (#4726).

* fix(command-registry): keep the readiness worst case in the ledger test

---------

Co-authored-by: Mistral Vibe <vibe@mistral.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant